<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>
  Class: Vertx::RecordParser
  
    &mdash; Ruby API Doc
  
</title>

  <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" />

  <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" />

<script type="text/javascript" charset="utf-8">
  hasFrames = window.top.frames.main ? true : false;
  relpath = '../';
  framesUrl = "../frames.html#!" + escape(window.location.href);
</script>


  <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script>

  <script type="text/javascript" charset="utf-8" src="../js/app.js"></script>


  </head>
  <body>
    <div id="header">
      <div id="menu">
  
    <a href="../_index.html">Index (R)</a> &raquo;
    <span class='title'><span class='object_link'><a href="../Vertx.html" title="Vertx (module)">Vertx</a></span></span>
     &raquo; 
    <span class="title">RecordParser</span>
  

  <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
</div>

      <div id="search">
  
    <a class="full_list_link" id="class_list_link"
        href="../class_list.html">
      Class List
    </a>
  
    <a class="full_list_link" id="method_list_link"
        href="../method_list.html">
      Method List
    </a>
  
    <a class="full_list_link" id="file_list_link"
        href="../file_list.html">
      File List
    </a>
  
</div>
      <div class="clear"></div>
    </div>

    <iframe id="search_frame"></iframe>

    <div id="content"><h1>Class: Vertx::RecordParser
  
  
  
</h1>

<dl class="box">
  
    <dt class="r1">Inherits:</dt>
    <dd class="r1">
      <span class="inheritName">Object</span>
      
        <ul class="fullTree">
          <li>Object</li>
          
            <li class="next">Vertx::RecordParser</li>
          
        </ul>
        <a href="#" class="inheritanceTree">show all</a>
      
      </dd>
    
  
  
    
  
    
  
  
  
    <dt class="r2 last">Defined in:</dt>
    <dd class="r2 last">src/main/api_shim/core/parsetools.rb</dd>
  
</dl>
<div class="clear"></div>

<h2>Overview</h2><div class="docstring">
  <div class="discussion">
    A helper class which allows you to easily parse protocols which are delimited by a sequence of bytes, or fixed
size records.

Instances of this class take as input <span class='object_link'><a href="Buffer.html" title="Vertx::Buffer (class)">Buffer</a></span> instances containing raw bytes, and output records.
For example, if I had a simple ASCII text protocol delimited by '\n' and the input was the following:

  buffer1:HELLO\nHOW ARE Y
  buffer2:OU?\nI AM
  buffer3: DOING OK
  buffer4:\n

Then the output would be:

  buffer1:HELLO
  buffer2:HOW ARE YOU?
  buffer3:I AM DOING OK

Instances of this class can be changed between delimited mode and fixed size record mode on the fly as
individual records are read, this allows you to parse protocols where, for example, the first 5 records might
all be fixed size (of potentially different sizes), followed by some delimited records, followed by more fixed
size records.

Instances of this class can't currently be used for protocols where the text is encoded with something other than
a 1-1 byte-char mapping.

  </div>
</div>
<div class="tags">
  
<p class="tag_title">Author:</p>
<ul class="author">
  
    <li>
      
      
      
      
        
        <div class='inline'><a href="http://tfox.org" target="_parent" title="Tim Fox">Tim Fox</a></div>
      
    </li>
  
</ul>

</div>






  
    <h2>
      Class Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#new_delimited-class_method" title="new_delimited (class method)">+ (RecordParser) <strong>new_delimited</strong>(delim, proc = nil, &amp;output_block) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>Create a new RecordParser instance, initially in delimited mode, and where the delimiter can be represented
by a delimiter string endcoded in latin-1 .</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#new_fixed-class_method" title="new_fixed (class method)">+ (RecordParser) <strong>new_fixed</strong>(size, proc = nil, &amp;output_block) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>Create a new RecordParser instance, initially in fixed size mode.</div></span>
  
</li>

      
    </ul>
  
    <h2>
      Instance Method Summary
      <small>(<a href="#" class="summary_toggle">collapse</a>)</small>
    </h2>

    <ul class="summary">
      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#delimited_mode-instance_method" title="#delimited_mode (instance method)">- (Object) <strong>delimited_mode</strong>(delim) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>Flip the parser into delimited mode.</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#fixed_size_mode-instance_method" title="#fixed_size_mode (instance method)">- (Object) <strong>fixed_size_mode</strong>(size) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>Flip the parser into fixed size mode.</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#input-instance_method" title="#input (instance method)">- (Object) <strong>input</strong>(data) </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>This method is called to provide the parser with data.</div></span>
  
</li>

      
        <li class="public ">
  <span class="summary_signature">
    
      <a href="#to_proc-instance_method" title="#to_proc (instance method)">- (Object) <strong>to_proc</strong> </a>
    

    
  </span>
  
  
  
  
  
  
  

  
    <span class="summary_desc"><div class='inline'>Convert it to a Proc.</div></span>
  
</li>

      
    </ul>
  



  <div id="class_method_details" class="method_details_list">
    <h2>Class Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="new_delimited-class_method">
  
    + (<tt><span class='object_link'><a href="" title="Vertx::RecordParser (class)">RecordParser</a></span></tt>) <strong>new_delimited</strong>(delim, proc = nil, &amp;output_block) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    Create a new RecordParser instance, initially in delimited mode, and where the delimiter can be represented
by a delimiter string endcoded in latin-1 . Don't use this if your String contains other than latin-1 characters.

  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>delim.</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>The delimiter string.</div>
      
    </li>
  
    <li>
      
        <span class='name'>proc</span>
      
      
        <span class='type'>(<tt>Proc</tt>)</span>
      
      
        <em class="default">(defaults to: <tt>nil</tt>)</em>
      
      
        &mdash;
        <div class='inline'>A proc to be used as the output handler</div>
      
    </li>
  
    <li>
      
        <span class='name'>output_block</span>
      
      
        <span class='type'>(<tt>Block</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>A block to be used as the output handler</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="" title="Vertx::RecordParser (class)">RecordParser</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>a new RecordParser</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


74
75
76
77</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/parsetools.rb', line 74</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_RecordParser constant id'>RecordParser</span><span class='dot token'>.</span><span class='rubyid_new_delimited identifier id'>new_delimited</span><span class='lparen token'>(</span><span class='rubyid_delim identifier id'>delim</span><span class='comma token'>,</span> <span class='rubyid_proc identifier id'>proc</span> <span class='assign token'>=</span> <span class='rubyid_nil nil kw'>nil</span><span class='comma token'>,</span> <span class='bitand op'>&amp;</span><span class='rubyid_output_block identifier id'>output_block</span><span class='rparen token'>)</span>
  <span class='rubyid_output_block identifier id'>output_block</span> <span class='assign token'>=</span> <span class='rubyid_proc identifier id'>proc</span> <span class='rubyid_if if_mod kw'>if</span> <span class='rubyid_proc identifier id'>proc</span>
  <span class='rubyid_RecordParser constant id'>RecordParser</span><span class='dot token'>.</span><span class='rubyid_new identifier id'>new</span><span class='lparen token'>(</span><span class='rubyid_org identifier id'>org</span><span class='dot token'>.</span><span class='rubyid_vertx identifier id'>vertx</span><span class='dot token'>.</span><span class='rubyid_java identifier id'>java</span><span class='dot token'>.</span><span class='rubyid_core identifier id'>core</span><span class='dot token'>.</span><span class='rubyid_parsetools identifier id'>parsetools</span><span class='dot token'>.</span><span class='rubyid_RecordParser constant id'>RecordParser</span><span class='dot token'>.</span><span class='rubyid_newDelimited identifier id'>newDelimited</span><span class='lparen token'>(</span><span class='rubyid_delim identifier id'>delim</span><span class='comma token'>,</span> <span class='rubyid_output_block identifier id'>output_block</span><span class='rparen token'>)</span><span class='rparen token'>)</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="new_fixed-class_method">
  
    + (<tt><span class='object_link'><a href="" title="Vertx::RecordParser (class)">RecordParser</a></span></tt>) <strong>new_fixed</strong>(size, proc = nil, &amp;output_block) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    Create a new RecordParser instance, initially in fixed size mode.

  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>size.</span>
      
      
        <span class='type'>(<tt>FixNum</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>The initial record size.</div>
      
    </li>
  
    <li>
      
        <span class='name'>proc</span>
      
      
        <span class='type'>(<tt>Proc</tt>)</span>
      
      
        <em class="default">(defaults to: <tt>nil</tt>)</em>
      
      
        &mdash;
        <div class='inline'>A proc to be used as the output handler</div>
      
    </li>
  
    <li>
      
        <span class='name'>output_block</span>
      
      
        <span class='type'>(<tt>Block</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>A block to be used as the output handler</div>
      
    </li>
  
</ul>

<p class="tag_title">Returns:</p>
<ul class="return">
  
    <li>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="" title="Vertx::RecordParser (class)">RecordParser</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>a new RecordParser</div>
      
    </li>
  
</ul>

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


84
85
86
87</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/parsetools.rb', line 84</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_RecordParser constant id'>RecordParser</span><span class='dot token'>.</span><span class='rubyid_new_fixed identifier id'>new_fixed</span><span class='lparen token'>(</span><span class='rubyid_size identifier id'>size</span><span class='comma token'>,</span> <span class='rubyid_proc identifier id'>proc</span> <span class='assign token'>=</span> <span class='rubyid_nil nil kw'>nil</span><span class='comma token'>,</span> <span class='bitand op'>&amp;</span><span class='rubyid_output_block identifier id'>output_block</span><span class='rparen token'>)</span>
  <span class='rubyid_output_block identifier id'>output_block</span> <span class='assign token'>=</span> <span class='rubyid_proc identifier id'>proc</span> <span class='rubyid_if if_mod kw'>if</span> <span class='rubyid_proc identifier id'>proc</span>
  <span class='rubyid_RecordParser constant id'>RecordParser</span><span class='dot token'>.</span><span class='rubyid_new identifier id'>new</span><span class='lparen token'>(</span><span class='rubyid_org identifier id'>org</span><span class='dot token'>.</span><span class='rubyid_vertx identifier id'>vertx</span><span class='dot token'>.</span><span class='rubyid_java identifier id'>java</span><span class='dot token'>.</span><span class='rubyid_core identifier id'>core</span><span class='dot token'>.</span><span class='rubyid_parsetools identifier id'>parsetools</span><span class='dot token'>.</span><span class='rubyid_RecordParser constant id'>RecordParser</span><span class='dot token'>.</span><span class='rubyid_newFixed identifier id'>newFixed</span><span class='lparen token'>(</span><span class='rubyid_size identifier id'>size</span><span class='comma token'>,</span> <span class='rubyid_output_block identifier id'>output_block</span><span class='rparen token'>)</span><span class='rparen token'>)</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

  <div id="instance_method_details" class="method_details_list">
    <h2>Instance Method Details</h2>

    
      <div class="method_details first">
  <h3 class="signature first" id="delimited_mode-instance_method">
  
    - (<tt>Object</tt>) <strong>delimited_mode</strong>(delim) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    Flip the parser into delimited mode. This method can be called multiple times with different values
of delim while data is being parsed.

  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>delim.</span>
      
      
        <span class='type'>(<tt>String</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>The delimiter string.</div>
      
    </li>
  
</ul>


</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


92
93
94</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/parsetools.rb', line 92</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_delimited_mode identifier id'>delimited_mode</span><span class='lparen token'>(</span><span class='rubyid_delim identifier id'>delim</span><span class='rparen token'>)</span>
  <span class='rubyid_@java_parser ivar id'>@java_parser</span><span class='dot token'>.</span><span class='rubyid_delimitedMode identifier id'>delimitedMode</span><span class='lparen token'>(</span><span class='rubyid_delim identifier id'>delim</span><span class='rparen token'>)</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="fixed_size_mode-instance_method">
  
    - (<tt>Object</tt>) <strong>fixed_size_mode</strong>(size) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    Flip the parser into fixed size mode. This method can be called multiple times with different values
of size while data is being parsed.

  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>size.</span>
      
      
        <span class='type'>(<tt>FixNum</tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>The record size.</div>
      
    </li>
  
</ul>


</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


99
100
101</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/parsetools.rb', line 99</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_fixed_size_mode identifier id'>fixed_size_mode</span><span class='lparen token'>(</span><span class='rubyid_size identifier id'>size</span><span class='rparen token'>)</span>
  <span class='rubyid_@java_parser ivar id'>@java_parser</span><span class='dot token'>.</span><span class='rubyid_fixedSizeMode identifier id'>fixedSizeMode</span><span class='lparen token'>(</span><span class='rubyid_size identifier id'>size</span><span class='rparen token'>)</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="input-instance_method">
  
    - (<tt>Object</tt>) <strong>input</strong>(data) 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    This method is called to provide the parser with data.

  </div>
</div>
<div class="tags">
  <p class="tag_title">Parameters:</p>
<ul class="param">
  
    <li>
      
        <span class='name'>data.</span>
      
      
        <span class='type'>(<tt><span class='object_link'><a href="Buffer.html" title="Vertx::Buffer (class)">Buffer</a></span></tt>)</span>
      
      
      
        &mdash;
        <div class='inline'>Input data to the parser.</div>
      
    </li>
  
</ul>


</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


64
65
66</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/parsetools.rb', line 64</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_input identifier id'>input</span><span class='lparen token'>(</span><span class='rubyid_data identifier id'>data</span><span class='rparen token'>)</span>
  <span class='rubyid_@java_parser ivar id'>@java_parser</span><span class='dot token'>.</span><span class='rubyid_handle identifier id'>handle</span><span class='lparen token'>(</span><span class='rubyid_data identifier id'>data</span><span class='dot token'>.</span><span class='rubyid__to_java_buffer identifier id'>_to_java_buffer</span><span class='rparen token'>)</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
      <div class="method_details ">
  <h3 class="signature " id="to_proc-instance_method">
  
    - (<tt>Object</tt>) <strong>to_proc</strong> 
  

  

  
</h3><div class="docstring">
  <div class="discussion">
    Convert it to a Proc

  </div>
</div>
<div class="tags">
  

</div><table class="source_code">
  <tr>
    <td>
      <pre class="lines">


56
57
58
59
60</pre>
    </td>
    <td>
      <pre class="code"><span class="info file"># File 'src/main/api_shim/core/parsetools.rb', line 56</span>

<span class='rubyid_def def kw'>def</span> <span class='rubyid_to_proc identifier id'>to_proc</span>
  <span class='rubyid_return return kw'>return</span> <span class='rubyid_Proc constant id'>Proc</span><span class='dot token'>.</span><span class='rubyid_new identifier id'>new</span> <span class='rubyid_do do kw'>do</span> <span class='bitor op'>|</span><span class='rubyid_data identifier id'>data</span><span class='bitor op'>|</span>
    <span class='rubyid_input identifier id'>input</span><span class='lparen token'>(</span><span class='rubyid_data identifier id'>data</span><span class='rparen token'>)</span>
  <span class='rubyid_end end kw'>end</span>
<span class='rubyid_end end kw'>end</span>
</pre>
    </td>
  </tr>
</table>
</div>
    
  </div>

</div>

    <div id="footer">
  Generated on Wed Jul 17 20:30:37 2013 by
  <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
  0.8.6.1 (ruby-1.9.3).
</div>

  </body>
</html>